import React, { Component } from "react";

export default class CreateRef extends Component {
  constructor(props) {
    super();
    this.inputRef = React.createRef();
    console.log(this.inputRef); // {current: null}
  }

  clickHandle = () => {
    console.log(this.inputRef); // {current: input}
    this.inputRef.current.focus();
  };

  render() {
    return (
      <div>
      <h2>官方推荐的 createRef API</h2>
        <input type="text" ref={this.inputRef} />
        <button onClick={this.clickHandle}>聚焦</button>
      </div>
    );
  }
}
